home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / Hack / UNIX / WZAP.ZIP / WZAP.C
C/C++ Source or Header  |  1996-04-26  |  970b  |  46 lines

  1. /*  Dave's neato wtmp program  
  2.  *    wzap.c  
  3.  *    NOTE:      reads 'wtmp' from current directory and writes
  4.  *            'wtmp.out' in cuurent directory...
  5.  */
  6.  
  7. #include    <utmp.h>
  8. #include    <stdio.h>
  9. #include    <time.h>
  10. #include    <sys/time.h>
  11.  
  12. FILE *Wfile, *Wout;
  13.  
  14. struct utmp myutmp;
  15.  
  16. main(argc,argv) 
  17. int argc;
  18. char *argv[];
  19. {
  20.     char username[20];
  21.     char yesorno[5];
  22.     long thetime, posi;
  23.  
  24.     if (argc<2) {
  25.         printf("\n\n");
  26.         printf("Enter username to zap from the wtmp: ");
  27.         scanf("%s",username);
  28.     } else strcpy(username,argv[1]);
  29.  
  30.     printf("\nopening file...\n");
  31.     if ((Wfile = fopen("wtmp","r"))==NULL)
  32.         { printf("no open file\n"); exit(0); }
  33.     printf("\opening output file...\n");
  34.     if ((Wout = fopen("wtmp.out","wr"))==NULL)
  35.         { printf("no open output file...\n"); exit(0); }
  36.  
  37.     printf("working...\n");
  38.     while(!feof(Wfile)) {
  39.         fread(&myutmp,sizeof(myutmp),1,Wfile);
  40.         if (strncmp(myutmp.ut_name,username,8))
  41.             fwrite(&myutmp,sizeof(myutmp),1,Wout); 
  42.     }
  43.     fclose(Wfile);
  44.     fclose(Wout);
  45. }
  46.